<!--		    removeFile(e){ 
		      	this.removeFile_fromList(e,this.prdConstruction) 
		    }
	-->
	<a-upload
	    multiple="multiple"
	    :action="uploadAddress"
	    :defaultFileList="defaultFileList"
	    :headers='headers'
	    :showUploadList='showUploadList'

	    :fileList='fileList' 
	    
	    :remove='removeFile'
	    @change="handleChangeFile"  
	    @preview='preview'  
	  >
	    <a-button> <a-icon type="upload" />上传文件</a-button><br>
	    <sub  class='mb28'  v-if='uptip'>（{{uptip}}）</sub>
	</a-upload>

</template>

<script >
import { download_file }  from '@/api/common'
 	export default {
		name:'fileUpload',
		props:{
			//是否支持多选文件，ie10+ 支持。开启后按住 ctrl 可选择多个文件。
			multiple:{
				type:Boolean,
				default:true
			}, 
			//默认已经上传的文件列表，****仅在初次渲染时有效
			defaultFileList:{
				type:[Object,Array],
				default:()=>[]
			},
			// 已经上传的文件列表（受控），一般使用
			fileList:{
				type:[Object,Array],
				default:()=>[]
			},
			//fileList 显示图标&删除按钮 setting
			showUploadList:{
				type:Object,
				default:()=>({
					showPreviewIcon: true, showRemoveIcon: true 
				})
			}, 

			 
			//默认上传提示文字
			uptip:{
				type:String,
				default:''
			},
			//当前上传仅支持单文件上传
			onefile:{
				type:Boolean,
				default:false
			}, 
		},
		data(){
			return {
				uploadAddress:process.env.BASE_API+'/op/fileupload/upload_file',/*upload_requesturl*/
				headers:{/*仅支持ie10+*/
					'X-Token':sessionStorage.getItem('token')
				} 
			}
		},
		created(){ 

		},
		methods:{ 
		    handleChangeFile(info) { 
		    	if(this.onefile){
		    		if(info.fileList.length>1){ 
			    		const h = this.$createElement;
				        this.$info({
				          title: '提示',
				          content: h('div', {}, [
				            h('p', '当前只允许上传一个文件，请确认删除后重试'),
				            // h('p', 'some messages...some messages...'),
				          ]),
				          okText:'知道了',
				          onOk() {},
				        });
			    		return false
			    	}
		    	}
		    	
				if (info.file.status == 'uploading') { 
					this.$emit('uploading',info)
				}
				if (info.file.status === 'done') {
					this.$message.success(`${info.file.name} 文件上传成功`); 
					// this.$emit('done',info.fileList)
				} else if (info.file.status === 'error') {
					this.$message.error(`${info.file.name} 文件上传失败.`);
				}
		    },
		    /*点击列表*/
		    preview(file){
		       download_file(file.code)
		    },
		    removeFile(file){ 
		    	let code = file.response ? file.response.data.code : file.code
		    	this.$emit('removeFile',code)
		    }
		}
	}
</script>